package eu.telecom_bretagne.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;


import android.os.Environment;

public class LogData {
	
	File logFile;
	PrintWriter output;
	Date date;
	long time;
	
	public LogData(String region) throws IOException{		
		Date myDate;		
		myDate = new Date();
		new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/Android/eu.telecom-bretagne.geotablet/").mkdir();
		String filename =  region + " " + myDate+ ".csv";
		File logFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/Android/eu.telecom-bretagne.geotablet/" + filename);
		output = new PrintWriter(new FileWriter(logFile));
		this.writeDataLine(region + myDate.getDate());
			
	}
	
	public synchronized void writeDataLine(String text){
		if (output!=null){
			time = new Date().getTime();
			String str = time + "," + text;
			output.println(str);
		}
		
	}
	
	public void closeFile () throws IOException{
		if (output!=null){
			output.close();
		}
	}

}

